﻿using System;
using System.Configuration;
using System.IO;

namespace Provausio.Server.Nzb.Poller.Object.Domain
{
    public class GenericLogger
    {
        public static void WriteLog(string path, string text)
        {
            if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(text)) return;

            var message = string.Format("{0} -- {1}", DateTime.Now, text);
            if (!Directory.Exists(Path.GetDirectoryName(path)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(path));
            }
            using (var file = new StreamWriter(path, true))
            {
                file.WriteLine(message);
            }
        }

        public static void WriteLog(string text)
        {
            var logPath = ConfigurationManager.AppSettings["LogPath"];
            WriteLog(logPath, text);
        }
    }
}
